

# 编码
a = "你好".encode("utf-8")
print(a)
# 解码
b = a.decode("utf-8")
print(b)

# 字符串的操作
# 创建-Create
x = "a"
y = "b"
z = x + y
print(z)

# 检索-Retrieve
m = "hello, world"
print(m[2])
print(m.find("l"))
print(m.find("z"))
print(m.index("w"))

# 更新-Update
n = "hello werld, hello werld"
print(n.replace("wer", "wor"))

o = "<<python>>, <<java>>, <<c++>>"
print(o.split(","))
p = o.split(",")
print(",".join(p))

# 删除-Delete
q = "      hello, world    "
print(q.strip())

# 字符串的输入与输出
# 保存到文件
input = open("input.txt", "w", encoding="utf-8")
content = "hello, world"
input.write(content)
input.close()

# 读取文件
output = open("input.txt", "r", encoding="utf-8")
content = output.read()
print(content)

# 追加文件
input = open("input.txt", "a", encoding="utf-8")
content = "\nhello, world"
input.write(content)
input.close()



# 格式化输出
# format
r = "ping"
s = "pong"
print("play pingpong: {}, {}".format(r, s))
print("play pingpong: {0}, {1}, {0}, {1}".format(r, s))
print("play pingpong: {a}, {b}, {a}, {b}".format(a="ping", b="pong"))
print(f"play pingpong: {r}, {s}")

# 小数的格式化输出
t = "{:.2f}".format(3.14159)
print(t)